package com.helloworld.test.util;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.ActionProvider;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;

public class MockMenuItem implements MenuItem {
	private Context context;
	private int itemId = 0;
	private int groupId = 0;
	private int order = 0;
	private CharSequence title;
	private CharSequence titleCondensed;
	private Drawable icon;
	private Intent intent;
	private char numericChar;
	private char alphaChar;
	private boolean checkable;
	private boolean checked;
	private boolean visible;
	private boolean enabled;
	private OnMenuItemClickListener menuItemClickListener;
	private View view;
	private ActionProvider actionProvider;
	private boolean expand = false;
	private OnActionExpandListener listener = new OnActionExpandListener() {
		public boolean onMenuItemActionExpand(MenuItem item) {
			return true;
		}

		public boolean onMenuItemActionCollapse(MenuItem item) {
			return true;
		}
	};

	public MockMenuItem(Context context) {
		this.context = context;
	}

	public MenuItem setItemId(int itemId) {
		this.itemId = itemId;
		return this;
	}

	public int getItemId() {
		return itemId;
	}

	public MenuItem setGroupId(int groupId) {
		this.groupId = groupId;
		return this;
	}

	public int getGroupId() {
		return groupId;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public int getOrder() {
		return order;
	}

	public MenuItem setTitle(CharSequence title) {
		this.title = title;
		return this;
	}

	public MenuItem setTitle(int title) {
		this.title = context.getText(title);
		return this;
	}

	public CharSequence getTitle() {
		return title;
	}

	public MenuItem setTitleCondensed(CharSequence title) {
		this.titleCondensed = title;
		return this;
	}

	public CharSequence getTitleCondensed() {
		return titleCondensed;
	}

	public MenuItem setIcon(Drawable icon) {
		this.icon = icon;
		return this;
	}

	public MenuItem setIcon(int iconRes) {
		this.icon = context.getResources().getDrawable(iconRes);
		return this;
	}

	public Drawable getIcon() {
		return icon;
	}

	public MenuItem setIntent(Intent intent) {
		this.intent = intent;
		return this;
	}

	public Intent getIntent() {
		return intent;
	}

	public MenuItem setShortcut(char numericChar, char alphaChar) {
		this.numericChar = numericChar;
		this.alphaChar = alphaChar;
		return this;
	}

	public MenuItem setNumericShortcut(char numericChar) {
		this.numericChar = numericChar;
		return this;
	}

	public char getNumericShortcut() {
		return numericChar;
	}

	public MenuItem setAlphabeticShortcut(char alphaChar) {
		this.alphaChar = alphaChar;
		return this;
	}

	public char getAlphabeticShortcut() {
		return alphaChar;
	}

	public MenuItem setCheckable(boolean checkable) {
		this.checkable = checkable;
		return this;
	}

	public boolean isCheckable() {
		return checkable;
	}

	public MenuItem setChecked(boolean checked) {
		this.checked = checked;
		return this;
	}

	public boolean isChecked() {
		return checked;
	}

	public MenuItem setVisible(boolean visible) {
		this.visible = visible;
		return this;
	}

	public boolean isVisible() {
		return visible;
	}

	public MenuItem setEnabled(boolean enabled) {
		this.enabled = enabled;
		return this;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public boolean hasSubMenu() {
		return false;
	}

	public SubMenu getSubMenu() {
		return null;
	}

	public MenuItem setOnMenuItemClickListener(
			OnMenuItemClickListener menuItemClickListener) {
		this.menuItemClickListener = menuItemClickListener;
		return this;
	}

	public OnMenuItemClickListener getMenuItemClickListener() {
		return menuItemClickListener;
	}

	public ContextMenuInfo getMenuInfo() {
		return null;
	}

	public void setShowAsAction(int actionEnum) {
	}

	public MenuItem setShowAsActionFlags(int actionEnum) {
		return this;
	}

	public MenuItem setActionView(View view) {
		this.view = view;
		return this;
	}

	public MenuItem setActionView(int resId) {
		this.view = LayoutInflater.from(context).inflate(resId, null, false);
		return this;
	}

	public View getActionView() {
		return view;
	}

	public MenuItem setActionProvider(ActionProvider actionProvider) {
		this.actionProvider = actionProvider;
		return this;
	}

	public ActionProvider getActionProvider() {
		return actionProvider;
	}

	public boolean expandActionView() {
		return expand = listener.onMenuItemActionExpand(this);
	}

	public boolean collapseActionView() {
		return !(expand = !listener.onMenuItemActionCollapse(this));
	}

	public boolean isActionViewExpanded() {
		return expand;
	}

	public MenuItem setOnActionExpandListener(OnActionExpandListener listener) {
		this.listener = listener;
		return this;
	}
}
